package com.stylefeng.guns.modular.vpn_order_info.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.DatasourceEnum;
import com.stylefeng.guns.core.mutidatasource.annotion.DataSource;
import com.stylefeng.guns.modular.vpn.dto.VpnOrderSearchDTO;
import com.stylefeng.guns.modular.vpn.utils.PoiExcelUtil;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.VpnOrderInfo;
import com.stylefeng.guns.modular.vpn_order_info.service.IVpnOrderInfoService;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 订单管理控制器
 *
 * @author fengshuonan
 * @Date 2020-03-02 16:23:55
 */
@Controller
@RequestMapping("/vpnOrderInfo")
public class VpnOrderInfoController extends BaseController {

    private String PREFIX = "/vpn_order_info/vpnOrderInfo/";

    @Autowired
    private IVpnOrderInfoService vpnOrderInfoService;

    /**
     * 跳转到订单管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "vpnOrderInfo.html";
    }

    /**
     * 获取订单管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(VpnOrderSearchDTO searchDTO) {
        return vpnOrderInfoService.findAllOrderInfo(searchDTO);
    }

    @ResponseBody
    @RequestMapping("/filterInfo")
    public Object getFilterInfo(){
        return vpnOrderInfoService.getFilterInfo();
    }

    @RequestMapping("/download/order")
    @ResponseBody
    public void downloadOrderInfo(@RequestParam(value = "userName",required = false) String userName,
                                  @RequestParam(value = "packageId",required = false) String packageId,
                                  @RequestParam(value = "paymentType",required = false) String paymentType,
                                  @RequestParam(value = "orderStatus",required = false) String orderStatus,
                                  @RequestParam(value = "beginTime",required = false) String beginTime,
                                  @RequestParam(value = "endTime",required = false) String endTime,
                                  HttpServletResponse response){
        vpnOrderInfoService.exportOrderInfo(userName,packageId,paymentType,orderStatus,beginTime,endTime,response);
    }
}
